#include "SelectionSet.h"
#include <algorithm>


SelectionSet::SelectionSet()
{
}


void SelectionSet::add(osg::Node* pNode)
{
	m_Selection.push_back(pNode);
	prune();
}


void SelectionSet::remove(osg::Node* pNode)
{
	m_Selection.erase( std::find(m_Selection.begin(), m_Selection.end(), pNode) );
	prune();
}


bool SelectionSet::containsNode(osg::Node *pNode) const
{
	NodeSet::const_iterator it = std::find(m_Selection.begin(), m_Selection.end(), pNode);
	return it != m_Selection.end();
}


// erase null-observer pointers
void SelectionSet::prune()
{
	m_Selection.erase(
		std::remove_if(m_Selection.begin(), m_Selection.end(),
			std::not1( std::mem_fun_ref(&osg::observer_ptr<osg::Node>::valid) )),
		m_Selection.end());
}
